package com.queue;

import java.util.concurrent.ConcurrentLinkedQueue;
/**
 * @Author: hanll
 * @ClassName: Queue
 * @Date: 2022-11-03 10:39
 * @Version: 1.0
 * @Description:
 */
public class Queue {

    private ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();

    private ThreadConfigUtils threadConfigUtils = new ThreadConfigUtils();

    public boolean put(String id) {
        boolean b = queue.add(id);
        return b;
    }

    public void get() {
        for (int i = 0; i < 5; i++) {
            Runnable runnable = () -> System.out.println(queue.poll());
            threadConfigUtils.initThread(runnable);
        }
    }

    public Integer size() {
        return queue.size();
    }

    public void shutdown() {
        threadConfigUtils.shutdown();
    }

    public static void main(String[] args) throws InterruptedException {
        Queue queue = new Queue();
        queue.put("1");
        queue.put("2");
        queue.put("3");
        queue.put("4");
        queue.put("5");
        queue.get();
        Thread.sleep(10000);
        if (queue.size() <= 0) {
            queue.shutdown();
        }
    }
}
